<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');

class User_model extends CI_Model {

	public function _newuser($username,$password,$first_name,$last_name,$email,$priority,$verification_code){
		$date = date("Y-m-d G:i:s");
		$values = array(
			'id' => '',
			'username' => $username,
			'password' => $password,
			'first_name' => $first_name,
			'last_name' => $last_name,
			'email' => $email,
			'bio' => '',
			'image' => '',
			'image_thumb' => '',
			'verification_code' => '',
			'priority_id' => $priority,
			'updated_at' => 'CURRENT_TIMESTAMP',
			'created_at' => $date
		);	
		if($this->db-insert('users',$values))
			return true;
		else
			return false;
	}
	
	function _insertCurrentGame($username,$kill_code){
		//Insert player into current_game table
		$date = date("Y-m-d G:i:s");	
		$records = $this->db->get_where("Users",array('username'=> $username));
			foreach ($records->result() as $row) {
				$user_id = $row->id;
			}
		$values = array(
			'id' => '',
			'users_id' => $user_id,
			'game_id' => 0,
			'status_id' => 1,
			'tags' => 0,
			'fed'=>0,
			'time_tagged' => '0000-00-00 00:00:00',
			'starve_time' => '0000-00-00 00:00:00',
			'killcode' => $kill_code,
			'updated_at' => 'CURRENT_TIMESTAMP',
			'created_at' => $date
			);
			if($this->db->insert('current_game',$values)){
				return true;	
			}else{
				return false;	
			}
	}
	
	public function _createLeaderboardEntry($username){
		$records = $this->db->get_where("Users",array('username'=> $username));
			foreach ($records->result() as $row) {
				$user_id = $row->id;
			}
			$values = array(
				'id' => '',
				'user_id' => $user_id,
				'tags' => 0,
				'fed' => 0,
				'survived' => 0,
				'games_played' => 0,
				'time_alive' => '0000-00-00 00:00:00'
			);
			
			if($this->db->insert('leaderboard',$values)){
				return true;	
			}else{
				return false;
			}
	}
	

/* End of file welcome.php */
/* Location: ./application/controllers/welcome.php */